import recast from "recast";

export function generateApiOptionsCode(api) {
  const apiModuleName = api.module_name;
  const apiAlias = api.alias;

  const code = `/* eslint-disable */


  (function() {
      var factory = function(getters) {
          return {
              simulateRequestValidator: {}
          };
      };
  
      var defineModule = new Function("return this")().defineModule;
      var pluginName = "nl:${apiModuleName}/${apiAlias}$options";
  
      if (typeof define === "function") {
          define([], function() {
              var v = factory(Array.prototype.map.call(arguments, function(r) {
                  return function() {
                      return r;
                  };
              }));
  
              if (typeof defineModule === "function") defineModule(pluginName, [], function() {
                  return v;
              });
  
              return v;
          });
      } else if (typeof defineModule === "function") defineModule(pluginName, [], factory, defineModule.isEnvNode() ? {
          module: module
      } : null);
  })();`;
    const node = recast.parse(code);
    return recast.prettyPrint(node).code;
}

export function generateApiOptionsFilename(api) {
  return `api.${ api.number || api.number_no }.${ api.alias }.options.js`;
}
